<?php
namespace App\Admin\Controllers;

use App\Admin\Filters\AdminOperationLogFilter;
use App\Admin\Models\AdminOperationLog;
use App\Admin\Requests\AdminOperationLogRequest;
use App\Admin\Resources\AdminOperationLogResource;

class AdminOperationLogController extends Controller
{
    public function store(
        AdminOperationLogRequest $request, 
        AdminOperationLog $adminOperationLog
    ){
        $inputs = $request->validated();
        $adminOperationLog = $adminOperationLog->add($inputs);

        return $this->created(
            AdminOperationLogResource::make($adminOperationLog)
        );
    }

    public function create()
    {
        return $this->ok();
    }

    public function update(
        AdminOperationLogRequest $request, 
        AdminOperationLog $adminOperationLog
    ){
        $inputs = $request->validated();
        $adminOperationLog->update($inputs);

        return $this->created(
            AdminOperationLogResource::make($adminOperationLog)
        );
    }

    public function edit(AdminOperationLog $adminOperationLog)
    {
        return $this->ok(
            AdminOperationLogResource::make($adminOperationLog)
        );
    }
    
    public function destroy(
        AdminOperationLog $adminOperationLog
    ){
        $adminOperationLog->delete();
        return $this->noContent();
    }

    public function index(
        AdminOperationLogFilter $filter,
    ){
        $adminOperationLogs = AdminOperationLog::withTrashed(isRestore())
            ->filter($filter)
            ->paginate();

        return $this->ok(
            AdminOperationLogResource::forCollection(
                AdminOperationLogResource::FOR_INDEX, $adminOperationLogs
            )
        );
        
    }

    public function show(
        Int $id
    ){
        $adminOperationLog = AdminOperationLog::withTrashed(isRestore())
            ->find($id);
        return $this->ok(
            AdminOperationLogResource::make($adminOperationLog)
            ->for(AdminOperationLogResource::FOR_SHOW)
        );
    }
}
